|
1
|
|
|
/*jslint |
|
2
|
|
|
indent: 4 |
|
3
|
|
|
*/ |
|
4
|
|
|
|
|
5
|
|
|
/*global |
|
6
|
|
|
$, google, |
|
7
|
|
|
Cookies, Coordinates, Lines, |
|
8
|
|
|
id2alpha |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
function Marker(parent, id) { |
|
12
|
|
|
'use strict'; |
|
13
|
|
|
|
|
14
|
|
|
this.m_parent = parent; |
|
15
|
|
|
this.m_id = id; |
|
16
|
|
|
this.m_alpha = id2alpha(id); |
|
17
|
|
|
this.m_free = true; |
|
18
|
|
|
this.m_name = ""; |
|
19
|
|
|
this.m_marker = null; |
|
20
|
|
|
this.m_circle = null; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
Marker.prototype.toString = function () { |
|
25
|
|
|
'use strict'; |
|
26
|
|
|
|
|
27
|
|
|
return this.getAlpha() + ":" + this.getPosition().lat().toFixed(6) + ":" + this.getPosition().lng().toFixed(6) + ":" + this.getRadius() + ":" + this.getName(); |
|
28
|
|
|
}; |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
Marker.prototype.toXmlWpt = function () { |
|
32
|
|
|
'use strict'; |
|
33
|
|
|
|
|
34
|
|
|
var data = ''; |
|
35
|
|
|
data += '<wpt lat="' + this.getPosition().lat().toFixed(8) + '" lon="' + this.getPosition().lng().toFixed(8) + '">\n'; |
|
36
|
|
|
data += ' <name>' + this.getName() + '</name>\n'; |
|
37
|
|
|
data += ' <sym>flag</sym>\n'; |
|
38
|
|
|
if (this.getRadius() > 0) { |
|
39
|
|
|
data += ' <extensions>\n'; |
|
40
|
|
|
data += ' <wptx1:WaypointExtension>\n'; |
|
41
|
|
|
data += ' <wptx1:Proximity>' + this.getRadius() + '</wptx1:Proximity>\n'; |
|
42
|
|
|
data += ' </wptx1:WaypointExtension>\n'; |
|
43
|
|
|
data += ' </extensions>\n'; |
|
44
|
|
|
} |
|
45
|
|
|
data += '</wpt>'; |
|
46
|
|
|
|
|
47
|
|
|
return data; |
|
48
|
|
|
}; |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
Marker.prototype.isFree = function () { |
|
52
|
|
|
'use strict'; |
|
53
|
|
|
|
|
54
|
|
|
return this.m_free; |
|
55
|
|
|
}; |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
Marker.prototype.clear = function () { |
|
59
|
|
|
'use strict'; |
|
60
|
|
|
|
|
61
|
|
|
if (this.m_free) { |
|
62
|
|
|
return; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
this.m_free = true; |
|
66
|
|
|
this.m_marker.setMap(null); |
|
67
|
|
|
this.m_marker = null; |
|
68
|
|
|
this.m_circle.setMap(null); |
|
69
|
|
|
this.m_circle = null; |
|
70
|
|
|
|
|
71
|
|
|
$('#dyn' + this.m_id).remove(); |
|
72
|
|
|
|
|
73
|
|
|
Lines.updateLinesMarkerRemoved(this.m_id); |
|
74
|
|
|
this.m_parent.handleMarkerCleared(); |
|
75
|
|
|
}; |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
Marker.prototype.getId = function () { |
|
79
|
|
|
'use strict'; |
|
80
|
|
|
|
|
81
|
|
|
return this.m_id; |
|
82
|
|
|
}; |
|
83
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
Marker.prototype.getAlpha = function () { |
|
86
|
|
|
'use strict'; |
|
87
|
|
|
|
|
88
|
|
|
return this.m_alpha; |
|
89
|
|
|
}; |
|
90
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
Marker.prototype.getName = function () { |
|
93
|
|
|
'use strict'; |
|
94
|
|
|
|
|
95
|
|
|
return this.m_name; |
|
96
|
|
|
}; |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
Marker.prototype.setName = function (name) { |
|
100
|
|
|
'use strict'; |
|
101
|
|
|
|
|
102
|
|
|
this.m_name = name; |
|
103
|
|
|
this.update(); |
|
104
|
|
|
}; |
|
105
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
Marker.prototype.setPosition = function (position) { |
|
108
|
|
|
'use strict'; |
|
109
|
|
|
|
|
110
|
|
|
this.m_marker.setPosition(position); |
|
111
|
|
|
this.m_circle.setCenter(position); |
|
112
|
|
|
this.update(); |
|
113
|
|
|
}; |
|
114
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
Marker.prototype.getPosition = function () { |
|
117
|
|
|
'use strict'; |
|
118
|
|
|
|
|
119
|
|
|
return this.m_marker.getPosition(); |
|
120
|
|
|
}; |
|
121
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
Marker.prototype.setRadius = function (radius) { |
|
124
|
|
|
'use strict'; |
|
125
|
|
|
|
|
126
|
|
|
this.m_circle.setRadius(radius); |
|
127
|
|
|
this.update(); |
|
128
|
|
|
}; |
|
129
|
|
|
|
|
130
|
|
|
|
|
131
|
|
|
Marker.prototype.getRadius = function () { |
|
132
|
|
|
'use strict'; |
|
133
|
|
|
|
|
134
|
|
|
return this.m_circle.getRadius(); |
|
135
|
|
|
}; |
|
136
|
|
|
|
|
137
|
|
|
|
|
138
|
|
|
Marker.prototype.setNamePositionRadius = function (name, position, radius) { |
|
139
|
|
|
'use strict'; |
|
140
|
|
|
|
|
141
|
|
|
this.m_name = name; |
|
142
|
|
|
this.m_marker.setPosition(position); |
|
143
|
|
|
this.m_circle.setCenter(position); |
|
144
|
|
|
this.m_circle.setRadius(radius); |
|
145
|
|
|
this.update(); |
|
146
|
|
|
}; |
|
147
|
|
|
|
|
148
|
|
|
|
|
149
|
|
|
Marker.prototype.initialize = function (map, name, position, radius) { |
|
150
|
|
|
'use strict'; |
|
151
|
|
|
|
|
152
|
|
|
this.m_free = false; |
|
153
|
|
|
this.m_name = name; |
|
154
|
|
|
|
|
155
|
|
|
// marker.png is 26x10 icons (each: 33px x 37px) |
|
156
|
|
|
var self = this, |
|
157
|
|
|
iconw = 33, |
|
158
|
|
|
iconh = 37, |
|
159
|
|
|
offsetx = (this.m_id % 26) * iconw, |
|
160
|
|
|
offsety = Math.floor(this.m_id / 26) * iconh, |
|
161
|
|
|
color = "#0090ff"; |
|
162
|
|
|
|
|
163
|
|
|
this.m_marker = new google.maps.Marker({ |
|
164
|
|
|
position: position, |
|
165
|
|
|
map: map, |
|
166
|
|
|
icon: new google.maps.MarkerImage( |
|
167
|
|
|
"img/markers.png", |
|
168
|
|
|
new google.maps.Size(iconw, iconh), |
|
169
|
|
|
new google.maps.Point(offsetx, offsety), |
|
170
|
|
|
new google.maps.Point(0.5 * iconw, iconh - 1) |
|
171
|
|
|
), |
|
172
|
|
|
draggable: true |
|
173
|
|
|
}); |
|
174
|
|
|
|
|
175
|
|
|
google.maps.event.addListener(this.m_marker, "drag", function () { self.update(); }); |
|
176
|
|
|
google.maps.event.addListener(this.m_marker, "dragend", function () { self.update(); }); |
|
177
|
|
|
|
|
178
|
|
|
this.m_circle = new google.maps.Circle({ |
|
179
|
|
|
center: position, |
|
180
|
|
|
map: map, |
|
181
|
|
|
strokeColor: color, |
|
182
|
|
|
strokeOpacity: 1, |
|
183
|
|
|
fillColor: color, |
|
184
|
|
|
fillOpacity: 0.25, |
|
185
|
|
|
strokeWeight: 1, |
|
186
|
|
|
radius: radius |
|
187
|
|
|
}); |
|
188
|
|
|
}; |
|
189
|
|
|
|
|
190
|
|
|
|
|
191
|
|
|
Marker.prototype.update = function () { |
|
192
|
|
|
'use strict'; |
|
193
|
|
|
|
|
194
|
|
|
if (this.m_free) { |
|
195
|
|
|
return; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
var pos = this.m_marker.getPosition(), |
|
199
|
|
|
radius = this.m_circle.getRadius(); |
|
200
|
|
|
|
|
201
|
|
|
this.m_circle.setCenter(pos); |
|
202
|
|
|
|
|
203
|
|
|
Cookies.set('marker' + this.m_id, pos.lat().toFixed(6) + ":" + pos.lng().toFixed(6) + ":" + radius + ":" + this.m_name, {expires: 30}); |
|
204
|
|
|
$('#dyn' + this.m_id + ' > .view .name').html(this.m_name); |
|
205
|
|
|
$('#dyn' + this.m_id + ' > .view .coords').html(Coordinates.toString(pos)); |
|
206
|
|
|
$('#dyn' + this.m_id + ' > .view .radius').html(radius); |
|
207
|
|
|
$('#dyn' + this.m_id + ' > .edit .name').val(this.m_name); |
|
208
|
|
|
$('#dyn' + this.m_id + ' > .edit .coords').val(Coordinates.toString(pos)); |
|
209
|
|
|
$('#dyn' + this.m_id + ' > .edit .radius').val(radius); |
|
210
|
|
|
|
|
211
|
|
|
Lines.updateLinesMarkerMoved(this.m_id); |
|
212
|
|
|
}; |
|
213
|
|
|
|